layui.use(['table', 'admin', 'ax','laydate','element','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var element = layui.element
    var form = layui.form;

    //tab切换
    element.on('tab(doTabBrief)',function(data){
        console.log(data.index)
    })

    laydate.render({
        elem: '#startTime'
        ,value:new Date()
    });

    laydate.render({
        elem: '#endTime'
        ,value:new Date()
    });

    laydate.render({
        elem: '#startTime2'
        ,value:new Date()
    });

    laydate.render({
        elem: '#endTime2'
        ,value:new Date()
    });

    laydate.render({
        elem: '#startTime3'
        ,value:new Date()
    });

    laydate.render({
        elem: '#endTime3'
        ,value:new Date()
    });

    /**
     * 调度单表管理
     */
    var carrierRecFeeConfirm = {
        tableId: "carrierRecFeeConfirmTable"
    };

    /**
     * 初始化表格的列
     */
    carrierRecFeeConfirm.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: 'ID'},
            {field: 'operateName', sort: true, title: '所属项目', width: 150},
            {field: 'trainNumber', sort: true, title: '车次'},
            {field: 'processStatus', title: '流程状态', templet: '#dispatchNumberTpl'},
            {field: 'departDate', sort: true, title: '发车日期'},
            {field: 'departTime', sort: true, title: '发运时间', width: 150},
            {field: 'arrivalTime', sort: true, title: '到仓时间', width: 150},
            {field: 'dispatchNumber', title: '调度单号', width: 180},
            {field: 'customerOrder', title: '客户单号'},
            {field: 'plateNumber', title: '车牌号'},
            {field: 'siji', title: '司机'},
            {field: 'sijidianhua', title: '司机电话'},
            {field: 'chexing', title: '车型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'mileageRange', title: '里程区间'},
            {field: 'loadingType', title: '装车方'},
            {field: 'loadingNumber', title: '装车工号'},
            {field: 'loadingPersonnel', title: '装车人员'},
            {field: 'zhunzailiang', sort: true, title: '准载量'},
            {field: 'getUnits', title: '收货客户'},
            {field: 'city', title: '城市'},
            {field: 'county', title: '区县'},
            {field: 'toonum', sort: true, title: '合计数量'},
            {field: 'toovolume', sort: true, title: '合计体积', totalRow: true},
            {field: 'boxNumber', sort: true, title: '封箱数', totalRow: true},
            {field: 'carrierName', title: '承运商', width: 150},
            {field: 'lineName', title: '线路', width: 150},
            {field: 'price', sort: true, title: '单价'},
            {field: 'calcCost', sort: true, title: '计算运费', totalRow: true},
            {field: 'taxRate', sort: true, title: '税率'},
            {field: 'untaxAmt', sort: true, title: '未税金额', totalRow: true},
            {field: 'taxAmt', sort: true, title: '税额', totalRow: true},
            {align: 'center', toolbar: '#tableBar', title: '操作', width:90, fixed: 'right'},
        ]];
    };

    /**
     * 导出excel按钮
     */
    carrierRecFeeConfirm.exportExcel = function () {
        var checkRows = table.checkStatus(carrierRecFeeConfirm.tableId);
        if (checkRows.data.length > 0) {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        } else {
            var queryData = {};
            queryData['operateId'] = $("#operateId").val();
            queryData['condition'] = $("#condition").val();
            queryData['startTime'] = $("#startTime").val();
            queryData['endTime'] = $("#endTime").val();
            queryData['processStatus'] = '已推送';
            $.ajax({
                type: "POST",
                url: Feng.ctxPath + "/fiFreightConfirm/listAll",
                dataType:'json',
                data: queryData,
                beforeSend: function () {
                    //弹出加载中
                    index = layer.load(1, {
                        shade: [0.3, '#000'] //0.1透明度的白色背景
                    });
                },
                success: function (data) {
                    checkRows.data = data;
                    table.exportFile(tableResult.config.id, checkRows.data, 'xls');
                    layer.close(index);
                },
                error: function (data) {
                    console.log(data)
                }
            });
        }
    };

    carrierRecFeeConfirm.btnqueren = function () {
        var checkRows = table.checkStatus(carrierRecFeeConfirm.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要确认的数据");
        } else {
            var ids = checkRows.data.map(function(item) {
                return item.id;
            });
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/fiFreightConfirm/queren", function (data) {
                    if(data.success){
                        Feng.success("操作成功!");
                        table.reload(carrierRecFeeConfirm.tableId);
                    }else{
                        Feng.error("操作失败!" + data.message + "!");
                    }
                }, function (data) {
                    Feng.error("操作失败!" + data.responseJSON.message + "!");
                });
                ajax.set("ids", ids.join(","));
                ajax.start();
            };
            Feng.confirm("是否对选择的记录进行确认吗?", operation);
        }
    };

    // 导出excel
    $('#btnExp').click(function () {
        carrierRecFeeConfirm.exportExcel();
    });

    // 导出excel
    $('#btnqueren').click(function () {
        carrierRecFeeConfirm.btnqueren();
    });
    /**
     * 点击查询按钮
     */
    carrierRecFeeConfirm.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId").val();
        queryData['condition'] = $("#condition").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        queryData['processStatus'] = '已推送';
        table.reload(carrierRecFeeConfirm.tableId, {
            where: queryData, page: {curr: 1},
            done: function (res, curr, count) {
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + carrierRecFeeConfirm.tableId,
        url: Feng.ctxPath + "/fiFreightConfirm/list",
        page: true,
        limit: 60,
        limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        totalRow: true,
        // toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        defaultToolbar: ['filter', 'exports', 'print'],
        cellMinWidth: 100,
        cols: carrierRecFeeConfirm.initColumn(),
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        carrierRecFeeConfirm.search();
    });

    /*********
     * 已确认  start
     */
    /**
     * 调度单表管理
     */
    var carrierRecFeeConfirm2 = {
        tableId: "carrierRecFeeConfirmTable2"
    };

    /**
     * 初始化表格的列
     */
    carrierRecFeeConfirm2.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: 'ID'},
            {field: 'operateName', sort: true, title: '所属项目', width: 150},
            {field: 'trainNumber', sort: true, title: '车次'},
            {field: 'processStatus', title: '流程状态', templet: '#dispatchNumberTpl'},
            {field: 'departDate', sort: true, title: '发车日期'},
            {field: 'departTime', sort: true, title: '发运时间', width: 150},
            {field: 'arrivalTime', sort: true, title: '到仓时间', width: 150},
            {field: 'dispatchNumber', title: '调度单号', width: 180},
            {field: 'customerOrder', title: '客户单号'},
            {field: 'plateNumber', title: '车牌号'},
            {field: 'siji', title: '司机'},
            {field: 'sijidianhua', title: '司机电话'},
            {field: 'chexing', title: '车型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'mileageRange', title: '里程区间'},
            {field: 'loadingType', title: '装车方'},
            {field: 'loadingNumber', title: '装车工号'},
            {field: 'loadingPersonnel', title: '装车人员'},
            {field: 'zhunzailiang', sort: true, title: '准载量'},
            {field: 'getUnits', title: '收货客户'},
            {field: 'city', title: '城市'},
            {field: 'county', title: '区县'},
            {field: 'toonum', sort: true, title: '合计数量'},
            {field: 'toovolume', sort: true, title: '合计体积', totalRow: true},
            {field: 'boxNumber', sort: true, title: '封箱数', totalRow: true},
            {field: 'carrierName', title: '承运商', width: 150},
            {field: 'lineName', title: '线路', width: 150},
            {field: 'price', sort: true, title: '单价'},
            {field: 'calcCost', sort: true, title: '计算运费', totalRow: true},
            {field: 'taxRate', sort: true, title: '税率'},
            {field: 'untaxAmt', sort: true, title: '未税金额', totalRow: true},
            {field: 'taxAmt', sort: true, title: '税额', totalRow: true},
        ]];
    };

    /**
     * 导出excel按钮
     */
    carrierRecFeeConfirm2.exportExcel = function () {
        var checkRows = table.checkStatus(carrierRecFeeConfirm2.tableId);
        if (checkRows.data.length > 0) {
            table.exportFile(tableResult2.config.id, checkRows.data, 'xls');
        } else {
            var queryData = {};
            queryData['operateId'] = $("#operateId2").val();
            queryData['condition'] = $("#condition2").val();
            queryData['startTime'] = $("#startTime2").val();
            queryData['endTime'] = $("#endTime2").val();
            queryData['processStatus'] = '已确认';
            $.ajax({
                type: "POST",
                url: Feng.ctxPath + "/fiFreightConfirm/listAll",
                dataType:'json',
                data: queryData,
                beforeSend: function () {
                    //弹出加载中
                    index = layer.load(1, {
                        shade: [0.3, '#000'] //0.1透明度的白色背景
                    });
                },
                success: function (data) {
                    checkRows.data = data;
                    table.exportFile(tableResult2.config.id, checkRows.data, 'xls');
                    layer.close(index);
                },
                error: function (data) {
                    console.log(data)
                }
            });
        }
    };
    // 导出excel
    $('#btnExp2').click(function () {
        carrierRecFeeConfirm2.exportExcel();
    });
    /**
     * 点击查询按钮
     */
    carrierRecFeeConfirm2.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId2").val();
        queryData['condition'] = $("#condition2").val();
        queryData['startTime'] = $("#startTime2").val();
        queryData['endTime'] = $("#endTime2").val();
        queryData['processStatus'] = '已确认';
        table.reload(carrierRecFeeConfirm2.tableId, {
            where: queryData, page: {curr: 1},
            done: function (res, curr, count) {
            }
        });
    };

    // 渲染表格
    var tableResult2 = table.render({
        elem: '#' + carrierRecFeeConfirm2.tableId,
        url: Feng.ctxPath + "/fiFreightConfirm/list",
        page: true,
        limit: 60,
        limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        totalRow: true,
        // toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        defaultToolbar: ['filter', 'exports', 'print'],
        cellMinWidth: 100,
        cols: carrierRecFeeConfirm2.initColumn(),
    });

    // 搜索按钮点击事件
    $('#btnSearch2').click(function () {
        carrierRecFeeConfirm2.search();
    });

    /*********
     * 已确认  end
     */

    /*********
     * 已确认  start
     */
    /**
     * 调度单表管理
     */
    var carrierRecFeeConfirm3 = {
        tableId: "carrierRecFeeConfirmTable3"
    };

    /**
     * 初始化表格的列
     */
    carrierRecFeeConfirm3.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: 'ID'},
            {field: 'operateName', sort: true, title: '所属项目', width: 150},
            {field: 'trainNumber', sort: true, title: '车次'},
            {field: 'processStatus', title: '流程状态', templet: '#dispatchNumberTpl'},
            {field: 'departDate', sort: true, title: '发车日期'},
            {field: 'departTime', sort: true, title: '发运时间', width: 150},
            {field: 'arrivalTime', sort: true, title: '到仓时间', width: 150},
            {field: 'dispatchNumber', title: '调度单号', width: 180},
            {field: 'customerOrder', title: '客户单号'},
            {field: 'plateNumber', title: '车牌号'},
            {field: 'siji', title: '司机'},
            {field: 'sijidianhua', title: '司机电话'},
            {field: 'chexing', title: '车型'},
            {field: 'mileageTraveled', sort: true, title: '行驶里程'},
            {field: 'mileageRange', title: '里程区间'},
            {field: 'loadingType', title: '装车方'},
            {field: 'loadingNumber', title: '装车工号'},
            {field: 'loadingPersonnel', title: '装车人员'},
            {field: 'zhunzailiang', sort: true, title: '准载量'},
            {field: 'getUnits', title: '收货客户'},
            {field: 'city', title: '城市'},
            {field: 'county', title: '区县'},
            {field: 'toonum', sort: true, title: '合计数量'},
            {field: 'toovolume', sort: true, title: '合计体积', totalRow: true},
            {field: 'boxNumber', sort: true, title: '封箱数', totalRow: true},
            {field: 'carrierName', title: '承运商', width: 150},
            {field: 'lineName', title: '线路', width: 150},
            {field: 'price', sort: true, title: '单价'},
            {field: 'calcCost', sort: true, title: '计算运费', totalRow: true},
            {field: 'taxRate', sort: true, title: '税率'},
            {field: 'untaxAmt', sort: true, title: '未税金额', totalRow: true},
            {field: 'taxAmt', sort: true, title: '税额', totalRow: true},
        ]];
    };

    /**
     * 导出excel按钮
     */
    carrierRecFeeConfirm3.exportExcel = function () {
        var checkRows = table.checkStatus(carrierRecFeeConfirm3.tableId);
        if (checkRows.data.length > 0) {
            table.exportFile(tableResult3.config.id, checkRows.data, 'xls');
        } else {
            var queryData = {};
            queryData['operateId'] = $("#operateId3").val();
            queryData['condition'] = $("#condition3").val();
            queryData['startTime'] = $("#startTime3").val();
            queryData['endTime'] = $("#endTime3").val();
            queryData['processStatus'] = '已申诉';
            $.ajax({
                type: "POST",
                url: Feng.ctxPath + "/fiFreightConfirm/listAll",
                dataType:'json',
                data: queryData,
                beforeSend: function () {
                    //弹出加载中
                    index = layer.load(1, {
                        shade: [0.3, '#000'] //0.1透明度的白色背景
                    });
                },
                success: function (data) {
                    checkRows.data = data;
                    table.exportFile(tableResult2.config.id, checkRows.data, 'xls');
                    layer.close(index);
                },
                error: function (data) {
                    console.log(data)
                }
            });
        }
    };
    // 导出excel
    $('#btnExp3').click(function () {
        carrierRecFeeConfirm3.exportExcel();
    });
    /**
     * 点击查询按钮
     */
    carrierRecFeeConfirm3.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId3").val();
        queryData['condition'] = $("#condition3").val();
        queryData['startTime'] = $("#startTime3").val();
        queryData['endTime'] = $("#endTime3").val();
        queryData['processStatus'] = '已申诉';
        table.reload(carrierRecFeeConfirm3.tableId, {
            where: queryData, page: {curr: 1},
            done: function (res, curr, count) {
            }
        });
    };

    // 渲染表格
    var tableResult3 = table.render({
        elem: '#' + carrierRecFeeConfirm3.tableId,
        url: Feng.ctxPath + "/fiFreightConfirm/list",
        page: true,
        limit: 60,
        limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        totalRow: true,
        // toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        defaultToolbar: ['filter', 'exports', 'print'],
        cellMinWidth: 100,
        cols: carrierRecFeeConfirm3.initColumn(),
    });

    // 搜索按钮点击事件
    $('#btnSearch3').click(function () {
        carrierRecFeeConfirm3.search();
    });

    /*********
     * 已申诉  end
     */

    /*********
     * 承运商绩效  start
     */
    var FiCarrierPma = {
        tableId: "fiCarrierPmaTable"
    };

    /**
     * 初始化表格的列
     */
    FiCarrierPma.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: ''},
            {field: 'operateName', title: '所属项目'},
            {field: 'carrierName', title: '承运商名称'},
            {field: 'pmaDt', sort: true, title: '绩效月份'},
            {field: 'pmaAmt', sort: true, title: '绩效金额', totalRow: true},
            {field: 'createName', title: '创建用户'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'updateName', title: '修改用户'},
            {field: 'updateTime', sort: true, title: '修改时间'},
            {field: 'remark', sort: true, title: '备注'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    FiCarrierPma.search = function () {
        var queryData = {};
        queryData['operateId'] = $("#operateId4").val();
        queryData['pmaDt'] = $("#pmaDt4").val();
        table.reload(FiCarrierPma.tableId, {
            where: queryData, page: {curr: 1},
            done:function () {
            }
        });
    };

    // 渲染表格
    var tableResult4 = table.render({
        elem: '#' + FiCarrierPma.tableId,
        url: Feng.ctxPath + '/fiCarrierPma/list',
        page: true,
        limit: 60,
        limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        totalRow: true,
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: FiCarrierPma.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch4').click(function () {
        FiCarrierPma.search();
    });

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    carrierRecFeeConfirm.openEditDlg = function (data) {
        window.location.href = Feng.ctxPath + '/rec/carrierRecFeeConfirm/edit?id=' + data.id;
    };

    // 单击行事件
    table.on('row(' + carrierRecFeeConfirm.tableId + ')', function (obj) {
        var data = obj.data;
        $('div[lay-id="' + carrierRecFeeConfirm.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样
        $('div[lay-id="' + carrierRecFeeConfirm.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6" });//改变当前tr颜色
    });

    // 工具条点击事件
    table.on('tool(' + carrierRecFeeConfirm.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            layer.open({
                type: 2,
                title: '承运商申诉',
                area: ['1100px', '500px'],
                anim: 5,
                content: Feng.ctxPath + '/fiFreightConfirm/edit?id=' + data.id,
                end: function () {
                    table.reload(carrierRecFeeConfirm.tableId);
                }
            });
        }else if (layEvent === 'tooTimeLine') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/fiFreightDetails/tooTimeLine?detailsId=' + data.id,
            });
        }
    });

    // 工具条点击事件
    table.on('tool(' + carrierRecFeeConfirm2.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'tooTimeLine') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/fiFreightDetails/tooTimeLine?detailsId=' + data.id,
            });
        }
    });

    // 工具条点击事件
    table.on('tool(' + carrierRecFeeConfirm3.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'tooTimeLine') {
            layer.open({
                type: 2,
                title: '时序图',
                area: ['550px', '570px'],
                anim: 5,
                content: Feng.ctxPath + '/fiFreightDetails/tooTimeLine?detailsId=' + data.id,
            });
        }
    });
});
